package com.open.harmony.controller;


import com.open.harmony.business.service.OrderItemService;
import com.open.harmony.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/OrderItem")
public class OrderItemController {

    private final OrderItemService orderItemService;

    @Autowired
    public OrderItemController(OrderItemService orderItemService) {
        this.orderItemService = orderItemService;
    }

    @GetMapping("/findAll")
    Result findAllOrderList(Integer userId) {
        return orderItemService.findAll(userId);
    }

    @PutMapping("/addItem")
    Result addItem(Integer userId, Integer productId, Double num){
        return orderItemService.addItem(userId, productId, num);
    }

    @PostMapping("/addOrder")
    Result createToOrder(Integer userId){
        return orderItemService.payment(userId);
    }

    @DeleteMapping("/deleteItem")
    public Result deleteItem(Integer userId, Integer productId) {
        return orderItemService.delete(userId, productId);
    }

    @DeleteMapping("/deleteAll")
    public Result deleteAll(Integer userId) {
        return orderItemService.deleteAll(userId);
    }

}
